﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using SUMO.MediaBrowser.Foundation;
using SUMO.MediaBrowser.ViewModel;

namespace SUMO.MediaBrowser.Controls
{
    public partial class UmbracoImageEditorControl : ChildWindow
    {
        public string EditorName
        {
            get { return "Base Editor Control"; }
        }

        public EditingHierarchicalMediaItem DataItem
        {
            get
            {
                return DataContext as EditingHierarchicalMediaItem;
            }
            set
            {
                DataContext = value;
            }
        }

        public UmbracoImageEditorControl(EditingHierarchicalMediaItem dataItem)
        {
            InitializeComponent();
            
            DataContext = dataItem;
            
            Title = this.EditorName;
        }


        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

    
        private void DoButton_Click(object sender, RoutedEventArgs e)
        {
            // WriteableBitmap b = SetupRenderedTextBitmap("Umbraco", 40);
            
            WriteableBitmap b = new WriteableBitmap((int)EditorImage.ActualWidth, (int)EditorImage.ActualHeight);
            b.Render(EditorImage, new TranslateTransform());

            TextBlock txt1 = new TextBlock();
            txt1.Text = "Umbraco";
            txt1.FontSize = 40;
            txt1.Foreground = new SolidColorBrush(Colors.Black);
            txt1.Margin = new Thickness(10);
            
            b.Render(txt1, new TranslateTransform());
            b.Invalidate();

            //TODO: If we are going to handle multiple transitions here, we should really set the view to
            //      the WritableBitmap we are re-rendering, and then do a final Jpeg/Image save when the user
            //      is happy, but there are some considerations when doing this that make it a little more than
            //      trivial. We would then, do this saving to jpeg byte[] data on 'OK'.
            //      EditorImage.Source = b;

            DataItem.WorkingData = ImageManipulation.GetBase64Jpg(b);
        }
    }

    
}


